﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Imaginecup.gameState.recycling.Sprite.Behavior;
using Microsoft.Xna.Framework;
using Imaginecup.recycling.Object.Entity;
using Imaginecup.gameState.recycling.Sprite;
using Imaginecup.gameState.recycling.Sprite.Factory;
using Imaginecup.recycling.Object.Menu;
using Microsoft.Xna.Framework.Input;
using Imaginecup.util;
using Imaginecup.gameState.menu;
using Imaginecup.factory;

namespace Imaginecup.gameState.recycling.Object.UI
{
    public class PauseButton : IUpdate
    {
        private ObjectInfo m_SpriteInfo;
        private ISprite m_Sprite;

        public PauseButton()
        {
            m_SpriteInfo = new ObjectInfo( new Rectangle( 738, 8, 59, 59) );
            m_Sprite = (ISprite)SpriteFactory.GetInstance().GetObject(SpriteID.TOGGLE_SPRITE, m_SpriteInfo, "PauseButton");
            RenderDrawer.GetInstance().AddSprite(m_Sprite);
            Updater.GetInstance().AddUpdate(this);
        }

        public void Update(GameTime gameTime)
        {
            MouseState mouse = MouseInputHandler.GetInputHandler().MouseState;

            if (mouse.LeftButton == ButtonState.Pressed)
            {
                if (m_SpriteInfo.SourceRectangle.Contains(mouse.X, mouse.Y))
                {
                    // 스프라이트의 상태를 변경
                    (m_Sprite as IButton).SetButtonState(Button_State.PRESSED);
                }
            }
            else if (mouse.LeftButton == ButtonState.Released)
            {
                // 스프라이트의 상태를 변경
                if (m_SpriteInfo.SourceRectangle.Contains(mouse.X, mouse.Y))
                {
                    (m_Sprite as IButton).SetButtonState(Button_State.NONE);
                    MenuState menuState = (MenuState)StateFactory.GetStateFactory().GetObject(StateFactoryID.State_Menu);
                    shareData.StateShareData.GetShareData().GetGameStateMan().PushState(menuState);
                }
            }
        }
    }
}
